package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/maximum-number-of-operations-to-move-ones-to-the-end/?envType=daily-question&envId=2025-11-13
 * @create 2025/11/13 11:00
 * @since JDK17
 */

public class Solution50 {
    public int maxOperations(String s) {
        char[] arr = s.toCharArray();
        int ans = 0, cnt = 0;
        for (int i = arr.length - 2; i >= 0; i--) {
            if (arr[i] != '0') {
                if (arr[i + 1] != '1') {    // 有一个间隔
                    ans += ++cnt;
                } else {
                    ans += cnt;
                }
            }
        }

        return ans;
    }
}
